<template>
    <div class="business">
        <Form ref="formData" :model="formData" :label-width="110">
            <Row>
                <Col :xs="24">
                    <FormItem label="简述原因">
                        <Input :disabled="readOnly || disabled" type="textarea" class="business-textarea"
                               v-model="formData.remarks"/>
                    </FormItem>
                </Col>
                <Col :xs="24">
                    <FormItem label="申请资料:" required>
                        <Button type="primary" @click="openUploadModal">申请资料</Button>
                    </FormItem>
                </Col>
            </Row>
        </Form>
        <UploadFileModal ref="uploadFileModal" :modal="isUploadFileModalOpen" @closeModal="closeModal"
                         :param="fileParams" :isPreview="isPreview || readOnly"/>
    </div>
</template>

<script>
    import UploadFileModal from "_p/basic/pages/contract/common/uploadFileModal/uploadFileModal";

    export default {
        name: "",
        components: {
            UploadFileModal
        },
        props: {
            readOnly: {
                type: Boolean,
                require: true
            },
            Obj: {
                type: Object,
            }
        },
        data() {
            return {
                disabled: false,
                isPreview: false,
                isUploadFileModalOpen: false,
                fileParams: {},
                formData: {
                    reason: "",
                    application: null
                }
            };
        },
        mounted() {
            if (this.Obj.processStatus !== undefined && this.Obj.processStatus !== 'draft' && this.Obj.processStatus !== 'toBeRepaired') {
                this.isPreview = true;
                this.disabled = true;
            } else {
                this.isPreview = false;
                this.disabled = false;
            }
        },
        methods: {
            closeModal() {
                let l = this.$refs.uploadFileModal.getFileList()
                console.log('申请资料 文件长度为：', l);
                this.isUploadFileModalOpen = false;
            },
            openUploadModal() {
                if (this.Obj.caseNo || this.formData.caseNo) {
                    this.fileParams = {
                        belongNo: this.Obj.contractNo || this.formData.contractNo,
                        busiNo: this.Obj.caseNo || this.formData.caseNo,
                        busiType: 'cancelContract',
                        busiData: {},
                        busiNodes: 'cancelContract', //业务节点
                    };
                    this.isUploadFileModalOpen = true;
                } else {
                    this.$Modal.warning({
                        title: "警告",
                        content: "请先保存业务数据！"
                    });
                    return;
                }
            }
        }
    };
</script>

<style lang="less" scoped>
    .business form {
        width: 100%;

        .business-textarea {
            max-width: 100%;
        }
    }
</style>
